home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / misc / avmnfaxsrc1_33.lha / iffpstrings.c < prev    next >
C/C++ Source or Header  |  1994-05-25  |  4KB  |  186 lines

  1. /* $Header: pd:zvmrcs/iffpstrings.c,v 1.1 1993/04/07 18:47:36 rvillari Exp $ */
  2. /* iffpstrings.c
  3.  *
  4.  *  centralized message routine for IFFP modules
  5.  *  If you plan to add international language support to
  6.  *  your iffparse application, all of the iffparse module
  7.  *  strings are here and are accessed via the SI() macro in
  8.  *  iffp/iff.h which calls GetString() 
  9.  *
  10.  *  There is some #ifdef'd out code here which will be useful if you
  11.  *  decide to localize your application when locale.library is released.
  12.  *
  13.  *  37.9 4/92   - fixed IFFerr() error equivalence tests and null string
  14.  *  37.10  7/92 - fixes to localization routine
  15.  */
  16.  
  17.  
  18. /*
  19. #define LOCALIZED
  20. */
  21.  
  22. #define INCLUDENAME    "iffp/iffpstrings.h"
  23.  
  24. #ifdef LOCALIZED
  25. #define CATALOGNAME    "yourapp.catalog"
  26. #include <clib/locale_protos.h>
  27. #ifndef NO_SAS_PRAGMAS
  28. #include <pragmas/locale_pragmas.h>
  29. #endif
  30. #endif
  31.  
  32. /* Locale stuff */
  33. #define  IFFP_MODULES
  34. #define  STRINGARRAY
  35. #include INCLUDENAME
  36.  
  37. #ifdef LOCALIZED
  38. extern struct Library *LocaleBase;
  39. #endif
  40.  
  41. extern struct AppString AppStrings[];
  42. static APTR   catalog = NULL;
  43.  
  44. /* For reference
  45. struct AppString
  46. {
  47.     LONG   as_ID;
  48.     STRPTR as_Str;
  49. };
  50. */
  51.  
  52. #include "iffp/iff.h"
  53. #include <intuition/screens.h>
  54.  
  55. static UBYTE nullstring[] = {""};
  56.  
  57. /* OpenStrings - localizes strings
  58.  * Requires open locale.library to work, but safe to call without
  59.  * You may pass nulls as args if you have no localized application strings
  60.  */
  61.  
  62. #ifdef LOCALIZED
  63. void OpenStrings()
  64.    {
  65.    if((LocaleBase)&&(!catalog))
  66.     {
  67.     catalog = OpenCatalogA(NULL,CATALOGNAME,NULL);
  68.     }
  69.     }
  70. #endif
  71.  
  72. /* CloseStrings - release the localized strings 
  73.  * Make sure all error messages are printed BEFORE calling this function
  74.  */
  75. #ifdef LOCALIZED
  76. void CloseStrings()
  77.     {
  78.     if((LocaleBase)&&(catalog))
  79.     {
  80.         CloseCatalog(catalog);
  81.     }
  82.     }
  83. #endif
  84.  
  85. /*
  86.  * IFFerr
  87.  *
  88.  * Returns pointer to IFF Error string or NULL string (no error)
  89.  */
  90. UBYTE *IFFerr(LONG error)
  91. {
  92.     /*
  93.      * English error messages for possible IFFERR_#? returns from various
  94.      * IFF routines.  To get the index into this array, take your IFFERR
  95.      * code, negate it, and subtract one.
  96.      *  idx = -error - 1;
  97.      *
  98.      * To index localized string, then add MSG_IFFP_STDFIRST
  99.      */
  100.  
  101.     static UBYTE unknown[48];
  102.     UBYTE  *s = nullstring;
  103.  
  104.     if((error < 0)&&(error >= -12))
  105.         {
  106.         s=SI(((-error) - 1) + MSG_IFFP_STDFIRST);
  107.         }
  108.     else if(error == CLIENT_ERROR)
  109.         {
  110.         s=SI(MSG_IFFP_CLIENTERR);
  111.         }
  112.     else if(error == NOFILE)
  113.         {
  114.         s=SI(MSG_IFFP_NOFILE);
  115.         }
  116.     else if(error)
  117.         {
  118.         sprintf(unknown,SI(MSG_IFFP_UNKNOWNERR_D),error);
  119.         s=unknown;
  120.         }
  121.     return(s);
  122. }
  123.  
  124.  
  125. /* OpenScreen error messages
  126.  */
  127. UBYTE *openScreenErr(ULONG errorcode)
  128.    {
  129.    static UBYTE unknown[48];
  130.    UBYTE *s=NULL;
  131.  
  132.         switch ( errorcode )
  133.     {
  134.     case OSERR_NOMEM:
  135.         s=SI(MSG_IFFP_OSNOMEM);
  136.         break;
  137.     case OSERR_NOCHIPMEM:
  138.         s=SI(MSG_IFFP_OSNOCHIPMEM);
  139.         break;
  140.     case OSERR_NOMONITOR:
  141.         s=SI(MSG_IFFP_OSNOMONITOR);
  142.         break;
  143.     case OSERR_NOCHIPS:
  144.         s=SI(MSG_IFFP_OSNOCHIPS);
  145.         break;
  146.     case OSERR_PUBNOTUNIQUE:
  147.         s=SI(MSG_IFFP_OSPUBNOTUNIQUE);
  148.         break;
  149.     case OSERR_UNKNOWNMODE:
  150.         s=SI(MSG_IFFP_OSUNKNOWNMODE);
  151.         break;
  152.     default:
  153.         sprintf(unknown,SI(MSG_IFFP_OSUNKNOWNERR_D),errorcode);
  154.         s=unknown;
  155.     }
  156.     return(s);
  157.     }
  158.  
  159. static UBYTE *NULLSTRING = "";
  160.  
  161. UBYTE *GetString(ULONG id)
  162.     {
  163.     struct AppString *as;
  164.     UBYTE *s = NULLSTRING;
  165.     int k,l;
  166.  
  167.     l = sizeof(AppStrings) / sizeof(AppStrings[0]);
  168.     as = AppStrings;
  169.  
  170.     for(k=0; k<l; k++, as++)
  171.     {
  172.     if(as->as_ID == id)
  173.         {
  174.         s = as->as_Str;
  175.         break;
  176.         }
  177.     }
  178. #ifdef LOCALIZED
  179.     if((LocaleBase)&&(catalog)&&(*s))
  180.     {
  181.     s = GetCatalogStr(catalog,id,s);
  182.     }
  183. #endif
  184.     return(s);
  185.     }
  186.